<?php
/**
 * Defines Kodform_Validator_Minmax class
 *
 *
 * @copyright 	Copyright (c) 2006 Boris Tomic (kodmasin.net)
 * @category 	Kodform
 * @package 	Kodform
 * @author 		Boris Tomic
 * @license 	http://boris.kodmasin.net/kodform4:license The BSD License
 *
 */

require_once 'Kodform/Validator.php';

/**
 * validator which is checking is value in specified range
 * 
 * useful for numeric values. 
 *
 */
class Kodform_Validator_Minmax extends Kodform_Validator{
	protected $max;
	protected $min;
	/**
	 * creates validator object
	 *
	 * @param mixed $max sets maximum value (to be valid value must be < $max
	 * (not <= $max)
	 * @param mixed $min sets minimum value (to be valid value must be < $mmin
	 * (not <= $min)
	 * @param string $error message which will be used if value is invalid
	 */
	public function __construct($max, $min, $error){
		parent::__construct($error);
		$this->max = $max;
		$this->min = $min;
	}
	/**
	 * just validating method
	 *
	 * @param mixed $value
	 * @return boolean true if valid false if not
	 * 
	 * @see Kodform_Validator
	 */
	public function validate($value){
		if($value == "" || $value === null)
			return true;
		if($value < $this->max && $value > $this->min)
			return true;
		return false;
	}
}
